//
//  WPNewsTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/3/31.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPNewsDealingTableViewCell.h"

@interface WPNewsDealingTableViewCell ()
@property (nonatomic, strong) UIView * backView;/**< 背景图 */
@property (nonatomic, strong) UIImageView * posterImageView;/**< 海报图 */
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UILabel * detailLabel;/**< 详情 */

@property (nonatomic, strong) UITextField * ticketCountTextField;/**< 成功交易张数 */
@property (nonatomic, strong) UILabel * allTicketCountLabel;/**< 总票数 */
@property (nonatomic, strong) UITextField * ticketIntroTextField;/**< 票数说明 */
@property (nonatomic, strong) UITextField * joinCountTextField;/**< 参与人数 */
@property (nonatomic, strong) UITextField * daysTextField;/**< 剩余天数 */
@property (nonatomic, strong) UITextField * joinIntroTextField;/**< 参与人数说明 */
@property (nonatomic, strong) UITextField * leftDaysTextField;/**< 剩余天数说明 */
- (void)initializeAppearance;/**< 一般界面初始化 */
@end
@implementation WPNewsDealingTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    [self addSubview:self.backView];
    [self.backView addSubview:self.posterImageView];
    [self.backView addSubview:self.titleLabel];
    [self.backView addSubview:self.detailLabel];
    [self.backView addSubview:self.ticketCountTextField];
    [self.backView addSubview:self.allTicketCountLabel];
    [self.backView addSubview:self.joinCountTextField];
    [self.backView addSubview:self.daysTextField];
    [self.backView addSubview:self.ticketIntroTextField];
    [self.backView addSubview:self.joinIntroTextField];
    [self.backView addSubview:self.leftDaysTextField];
}
#pragma mark - responds events
- (void)respondsToAttention:(UIButton *)sender {
    
}
- (void)respondsToAddAttention:(UIButton *)sender {
    sender.selected = !sender.selected;
}
#pragma mark - private methods
- (void)setModelWithModel:(WPNewsDealingModel *)model {
    _posterImageView.image = IMAGE_NAME(model.posterImageName);
    _titleLabel.text = model.title;
    _detailLabel.text = model.detail;
    _ticketCountTextField.text = model.ticketCount;
    _allTicketCountLabel.attributedText = [self configAttributtedStringWithString:model.allTicketCount];
    _joinCountTextField.text = model.joinCount;
    _daysTextField.text = model.leftDays;
}
- (NSMutableAttributedString *)configAttributtedStringWithString:(NSString *)str {
    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@张", str]];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(242, 106, 89, 1) range:NSMakeRange(0, str.length)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(141, 141, 141, 1) range:NSMakeRange(str.length, 1)];
    return attributedStr;
}
#pragma mark - getter
- (UIView *)backView {
    if (!_backView) {
        _backView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 300*DHFlexibleHorizontalMutiplier(), 280*DHFlexibleHorizontalMutiplier())];
            view.layer.borderWidth = 1;
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.layer.borderColor = COLOR_RGB(224, 224, 224, 1).CGColor;
            view;
        });
    }
    return _backView;
}
- (UIImageView *)posterImageView {
    if (!_posterImageView) {
        _posterImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300*DHFlexibleHorizontalMutiplier(), 158*DHFlexibleHorizontalMutiplier())];
            view;
        });
    }
    return _posterImageView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.posterImageView.frame)+5*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:16*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(58, 58, 58, 1);
            lab;
        });
    }
    return _titleLabel;
}
- (UILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), 300*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.numberOfLines = 2;
            lab.textColor = COLOR_RGB(158, 158, 158, 1);
            lab;
        });
    }
    return _detailLabel;
}
- (UITextField *)ticketCountTextField {
    if (!_ticketCountTextField) {
        _ticketCountTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.detailLabel.frame), 60*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 15, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"张/";
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            text.rightView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _ticketCountTextField;
}
- (UILabel *)allTicketCountLabel {
    if (!_allTicketCountLabel) {
        _allTicketCountLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(60*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.detailLabel.frame), 60*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.userInteractionEnabled = NO;
            lab;
        });
    }
    return _allTicketCountLabel;
}
- (UITextField *)joinCountTextField {
    if (!_joinCountTextField) {
        _joinCountTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(150*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.detailLabel.frame), 60*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 15, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"人";
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            text.rightView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.textAlignment = NSTextAlignmentCenter;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _joinCountTextField;
}
- (UITextField *)daysTextField {
    if (!_daysTextField) {
        _daysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(220*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.detailLabel.frame), 50*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 15*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"天";
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            text.rightView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _daysTextField;
}
- (UITextField *)ticketIntroTextField {
    if (!_ticketIntroTextField) {
        _ticketIntroTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.allTicketCountLabel.frame), 105*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(141, 141, 141, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"成功交易 / 交易总数";
            text;
        });
    }
    return _ticketIntroTextField;
}
- (UITextField *)joinIntroTextField {
    if (!_joinIntroTextField) {
        _joinIntroTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.joinCountTextField.frame)*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.joinCountTextField.frame), 50*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            
            text.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(141, 141, 141, 1);
            text.userInteractionEnabled = NO;
            text.text = @"参与人数";
            text;
        });
    }
    return _joinIntroTextField;
}
- (UITextField *)leftDaysTextField {
    if (!_leftDaysTextField) {
        _leftDaysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(210*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.daysTextField.frame), 70*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(141, 141, 141, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"剩余时间";
            text;
        });
    }
    return _leftDaysTextField;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
